<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

if (reqVarInt('modifica')>0) {
	$sql_sel = "SELECT * FROM ovf_rss_url " .
			" WHERE id_rss = ".reqVarInt('modifica');
	$objDB->query($sql_sel,'selRec');
	if ($acX = $objDB->fetch('selRec')) {
		$_REQUEST['statoPagina'] = 'modifica';
		$_REQUEST['descr'] = $acX['descr'];
		$_REQUEST['url'] = $acX['url'];
		$_REQUEST['id_rss'] = $acX['id_rss'];
	}
}
if (reqVarInt('elimina')>0) {
	$sql_sel = "DELETE FROM ovf_rss_url " .
			" WHERE id_rss = ".reqVarInt('elimina');
	$objDB->query($sql_sel,'selRec');
	$sql_sel = "DELETE FROM ovf_utenti_rss " .
			" WHERE id_rss = ".reqVarInt('elimina');
	$objDB->query($sql_sel,'selRec');
	$_REQUEST['statoPagina'] = '';
	$_REQUEST['descr'] = '';
	$_REQUEST['url'] = '';
	$_REQUEST['id_rss'] = '';
}
if (reqVar('azione')=='aggrss') {
	if (reqVarTrim('descr')=='' || reqVarTrim('url')=='') {
		$msgPag .= _t('dati mancanti').'<br>';
	} else {
		$sql_sel = "INSERT INTO ovf_rss_url " .
				" SET descr = '".reqVarAS('descr')."', url = '".reqVarAS('url')."'";
		$objDB->query($sql_sel,'selRec');
		$_REQUEST['statoPagina'] = '';
		$_REQUEST['descr'] = '';
		$_REQUEST['url'] = '';
		$_REQUEST['id_rss'] = '';
	}
}
if (reqVar('azione')=='regmod') {
	if (reqVarTrim('descr')=='' || reqVarTrim('url')=='') {
		$msgPag .= _t('dati mancanti').'<br>';
	} else {
		$sql_sel = "UPDATE ovf_rss_url SET descr = '".reqVarAS('descr')."', url = '".reqVarAS('url')."'"
			." WHERE id_rss = ".reqVarInt('id_rss');
		$objDB->query($sql_sel,'selRec');
		$_REQUEST['statoPagina'] = '';
		$_REQUEST['descr'] = '';
		$_REQUEST['url'] = '';
		$_REQUEST['id_rss'] = '';
	}
}

$sql_sel = "SELECT * FROM ovf_rss_url " .
		" ORDER BY descr ";
$objDB->query($sql_sel,'selRec');

$cmdL = "";
$cmdR = "&nbsp;&nbsp;&nbsp;";
if (reqVar('statoPagina')=='modifica') {
	$cmdR .= "<a class=\"cmd1\" href=\"javascript:submAz('regmod');\">registra modifiche</a>";
	$cmdR .= "<a class=\"cmd1\" href=\"javascript:submAz('reload');\">annulla modifiche</a>";
} else {
	$cmdR .= "<a class=\"cmd1\" href=\"javascript:submAz('aggrss');\">aggiungi RSS</a>";
	$cmdR .= cmdTorna(); 
}

testaHtml('Gestione RSS','Lista RSS', $msgPag, 'gest');
?>
<script type="text/javascript">
<!--
function submAz(az) {
	document.frm1.azione.value = az;
	document.frm1.submit();
}
function confEli(id) {
	if (confirm("Confermi l'eliminazione ?")) {
		document.location.href = "rssList.php?elimina="+id+"&<?=$sXSNQS?>";
	}
}
//-->
</script>
<?
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('statoPagina');
echo getHtmlHidden('azione');
echo getHtmlHidden('id_rss');
echo getHtmlHidden('startoffset');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="lab1" colspan='2' width='2%' align='center'>&nbsp;</td>
      <td class="lab1" width='49%' align='center'>Descrizione</td>
      <td class="lab1" width='49%' align='center' >URL</td>
   </tr>
   <tr>
      <td class="lab1" colspan='2' width='2%' align='center'>&nbsp;</td>
      <td class="lab1" width='49%' align='center'><?=getHtmlText('descr',50)?></td>
      <td class="lab1" width='49%' align='center' ><?=getHtmlText('url',50)?></td>
   </tr>
         <? 
$clRF = 'txt2';
while($acX = $objDB->fetch('selRec')) { 
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>">
      	<a href='rssList.php?modifica=<?=$acX['id_rss']."&$sXSNQS"?>' class="<?=$clRF?>">
      		<img src='<?=OVF_URL_ROOT?>/app/_img/matita.png' border='0'></a>
      </td>
      <td class="<?=$clRF?>">
      	<a href="javascript:confEli('<?=$acX['id_rss']?>');" class="<?=$clRF?>">
      		<img src='<?=OVF_URL_ROOT?>/app/_img/elimina.gif' border='0'></a>
      </td>
      <td class="<?=$clRF?>"><? echo $acX['descr'];?></td>
      <td class="<?=$clRF?>"><? echo $acX['url'];?></td>
   </tr>
<? 
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
